package com.woniuxy.entity;

import jakarta.annotation.Nullable;
import jakarta.persistence.*;

import java.io.Serializable;


/**
 * @Author: 马宇航
 * @Todo: 用户类
 * @DateTime: 25/08/26/星期二 11:31
 * @Component: 成都蜗牛学苑
 **/
//本身是可以直接映射到数据库
@Entity
@Table(name = "userEntity")  //对应数据库的表名
public class UserEntity implements Serializable { //序列化必须打开
    private static final long serialVersionUID = 1L;
    @Id  //表示是主键
    //id主键的生成策略，是自增 还是uuid
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    //如果有驼峰下划线映射 就配置 Column字段
    @Column(name = "username")
    private String username;
    private String password;
    //1对1的外键（逻辑外键）,数据库字段名 按照注解来，而不是自动的 属性名字
    @Column(name = "hobby_id")
    private Integer hobbyId;
//    //不更新到数据库 字段 本user中的hobby_id就是Hobby表的id（referencedColumnName）
//    //如果只有name，默认对应Hobby表的对应hobby表的hobby_id。
//    @JoinColumn(name = "hobby_id",insertable = false,updatable = false,referencedColumnName = "id")
//    @OneToOne(targetEntity = Hobby.class)
//    private Hobby hobby;
    @Nullable
    @Column(name = "sex",nullable = true)
    private Integer sex;

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getHobbyId() {
        return hobbyId;
    }

    public void setHobbyId(Integer hobbyId) {
        this.hobbyId = hobbyId;
    }

//    public Hobby getHobby() {
//        return hobby;
//    }
//
//    public void setHobby(Hobby hobby) {
//        this.hobby = hobby;
//    }


    @Override
    public String toString() {
        return "UserEntity{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", hobbyId=" + hobbyId +
                ", sex=" + sex +
                '}';
    }
}
